/** page 组件 共同逻辑 */
export default {
  data: vm => ({
    // 数据表格
    tableData: {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ...vm.$route && vm.$route.query,
        ...vm.queryParamsDefault()
      },
      // 显示搜索条件
      queryShow: true,
      // 表格遮罩层
      loading: true,
      // 表格数据
      data: [],
      // 总条数
      total: 0,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true
    },
    formData: {
      // 表单遮罩层
      formLoading: true,
      // 弹出层标题
      formTitle: '',
      formKey: '',
      // 是否显示弹出层
      dialogVisible: false,
      // 表单校验
      rules: {
        xxx: [{ required: true, message: 'xxx不能为空', trigger: 'change' }]
      }
    }
  }),
  created () {
  },
  methods: {
    handleImport () {},
    /** 查询列表 */
    getList () {
      //  this.tableLoading = true
      //   api.list(this.queryParams).then(response => {
      //     this.tableData = response.data.records
      //     this.totalCount = response.data.total
      //     this.tableLoading = false
      //   })
    },
    /** 重置按钮 */
    reset () {
      this.resetFront()
      this.formData = {
        ...this.formDataDefault()
      }
      // this.formData.id = {
      //     id: this.formData.id
      // };
      this.resetAfter()
    },
    /** 重置按钮增强 */
    formDataDefault () { return {} },
    resetFront () {},
    resetAfter () {},
    /** 关闭按钮 */
    beforeClosed () {
      this.dialogVisible = false
      this.dialogVisibleDetail = false
      this.reset()
      // this.formData.id = undefined;
    },

    resetQueryForm () {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        ...this.queryParamsDefault()
      }
      this.resetQueryAfter()
    },
    queryParamsDefault () { return {} },
    resetQueryAfter () {},
    /** 重置按钮操作 */
    resetQuery () {
      this.resetQueryForm()
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd () {
      this.formLoading = false
      this.dialogVisible = true
      this.formKey = 'add'
      this.formTitle = '添加'
    },
    /** 详情按钮操作 */
    handleView (row) {
      this.formLoading = true
      this.formTitle = '详情'
      this.formKey = 'view'
      this.dialogVisible = true
      //  const id = row.id || this.ids
      //   api.info(id).then(response => {
      //     this.formData = response.data
      //     this.formData.uploadDtoList = response.data.fileDtoList
      //     this.formLoading = false
      //   })
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.formLoading = true
      this.formTitle = '修改'
      this.formKey = 'update'
      this.dialogVisible = true
      // this.formData = this.$utils.deepClone(row);
      // this.formLoading = false;
      this.handleUpdateApi(row)
      //   const id = row.id || this.ids
      //   api.info(id).then(response => {
      //     this.formData = response.data
      //     this.formLoading = false
      //   })
    },
    handleUpdateApi () {},
    /** 提交按钮 */
    submitForm () {
      console.log(this.queryParams)
      // this.$refs.form.validate(valid => {
      //   if (!valid) return false
      // if (this.formData.id != null) {
      //   api.update(this.formData).then(response => {
      //     this.msgSuccess('修改成功')
      //     this.dialogVisible = false
      //     this.getList()
      //   })
      // } else {
      //   api.add(this.formData).then(response => {
      //     this.msgSuccess('新增成功')
      //     this.dialogVisible = false
      //     this.getList()
      //   })
      // }
      // })
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      const ids = row.id || this.ids
      this.$confirm('是否确认删除编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function () {
        //   return api.del(ids)
        })
        .then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        })
    },
    /** 导出按钮操作 */
    handleExport () {
      const queryParams = this.queryParams
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        console.log(queryParams)
        // return api.export(queryParams)
      })
    },
    handleSizeChange (val) {
      this.queryParams.pageSize = val
      this.getList()
    },
    handleCurrentChange (val) {
      this.queryParams.pageNum = val
      this.getList()
    }
  }
}
